

<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>编辑分类</title>
  <meta name="renderer" content="webkit">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
  <link rel="stylesheet" href="../../layuiadmin/layui/css/layui.css" media="all">
  <link rel="stylesheet" href="../../layuiadmin/style/admin.css" media="all">
</head>
<body>
  <div class="layui-form" lay-filter="layuiadmin-app-form-list" id="layuiadmin-app-form-list" style="padding: 20px 30px 0 0;"> 
    <div class="layui-form-item">
      <label class="layui-form-label">属性显示名称</label>
      <div class="layui-input-inline">
        <input type="text" name="fCaShowName" id="fCaShowName" lay-verify="required" autocomplete="off" class="layui-input">
      </div>
    </div>
    <div class="layui-form-item">
      <label class="layui-form-label">属性名称</label>
      <div class="layui-input-inline">
        <input type="text" name="fCaName" id="fCaName" lay-verify="required"  autocomplete="off" class="layui-input">
      </div>
    </div>
    <div class="layui-form-item">
      <label class="layui-form-label">属性编码</label>
      <div class="layui-input-inline">
        <input type="text" name="fCaCode" id="fCaCode" lay-verify="required" autocomplete="off" class="layui-input">
      </div>
    </div>
    <div class="layui-form-item">
      <label class="layui-form-label">字段类型</label>
      <div class="layui-input-inline">
        <select name="fCaFieldType" id="typeList" lay-verify="required" lay-filter="typeList">
            <option value="">请选择</option>
        </select>
      </div>
    </div>
    <div class="layui-form-item">
      <label class="layui-form-label">默认值</label>
      <div class="layui-input-inline">
        <input type="text" name="fCaDefaultValue" lay-verify="required" autocomplete="off" class="layui-input">
      </div>
    </div>
    <div class="layui-form-item">
      <label class="layui-form-label">是否关键属性</label>
      <div class="layui-input-inline">
        <select name="fCaKeyField" lay-verify="required" id="fCakeyField">
          <option value="">请选择</option>
          <option value="1">是</option>
          <option value="0">否</option>
        </select>
      </div>
    </div>
    <div class="layui-form-item">
      <label class="layui-form-label">长度</label>
      <div class="layui-input-inline">
        <input type="text" name="fCaLength" lay-verify="required" autocomplete="off" class="layui-input">
      </div>
    </div>
    <div class="layui-form-item">
      <label class="layui-form-label">最大值</label>
      <div class="layui-input-inline">
        <input type="text" name="fCaMaxValue" lay-verify="required" autocomplete="off" class="layui-input">
      </div>
    </div>
    <div class="layui-form-item">
      <label class="layui-form-label">最小值</label>
      <div class="layui-input-inline">
        <input type="text" name="fCaMinValue" lay-verify="required" autocomplete="off" class="layui-input">
      </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">是否可以为空</label>
        <div class="layui-input-inline">
          <select name="fCaIsNull" lay-verify="required">
            <option value="">请选择</option>
            <option value="1">是</option>
            <option value="0">否</option>
          </select>
        </div>
      </div>
      <div class="layui-form-item">
        <label class="layui-form-label">是否唯一</label>
        <div class="layui-input-inline">
          <select name="fCaIsUniqueness" lay-verify="required">
            <option value="">请选择</option>
            <option value="1">是</option>
            <option value="0">否</option>
          </select>
        </div>
      </div>
      <div class="layui-form-item">
        <label class="layui-form-label">单位</label>
        <div class="layui-input-inline">
          <input type="text" name="fCaCompany" lay-verify="required" autocomplete="off" class="layui-input">
        </div>
      </div>
      <div class="layui-form-item layui-hide">
        <input type="button" lay-submit lay-filter="layuiadmin-app-form-submit" id="layuiadmin-app-form-submit" value="确认添加">
        <input type="button" lay-submit lay-filter="layuiadmin-app-form-edit" id="layuiadmin-app-form-edit" value="确认编辑">
      </div>
    </div>
  </div>
  <script src='../../layuiadmin/modules/jTools.js'></script>
  <script src="../../layuiadmin/layui/layui.js"></script>  
  <script>
      function initData(data){
        layui.use(['form','my_send'], function(){
          var $ = layui.$
          ,form = layui.form
          ,formfMcId = jTools.getQuery('fMcId')
        ,my_send = layui.my_send
                  , http_proxy = layui.http_proxy;
          $.ajax({
            url:http_proxy('/materialCaregory/getDataTypeList'),
            async: false,
            dataType:'json',
            type:'get',
            success:function(data){
              $.each(data.rows,function(index,item){
                $('#typeList').append(new Option(item.fName,item.fId));
              });
            }
          });
          data.fCaKeyField = data.fCaKeyField === '是' ? "1":"0";
          form.val("layuiadmin-app-form-list", {
            "fCaShowName": data.fCaShowName,
            "fCaName":data.fCaName,
            "fCaFieldType":data.fCaFieldType,
            "fCaDefaultValue":data.fCaDefaultValue,
            "fCaKeyField":data.fCaKeyField,
            "fCaLength":data.fCaLength,
            "fCaMaxValue":data.fCaMaxValue,
            "fCaMinValue":data.fCaMinValue,
            "fCaIsNull":data.fCaIsNull,
            "fCaIsUniqueness":data.fCaIsUniqueness,
            "fCaCompany":data. fCaCompany,
            "fCaOrder":data.fCaOrder,
            "fCaEnabled":data.fCaEnabled,
            "fCaCode":data.fCaCode
          });
          form.render('select');
        });
      }
      layui.config({
        base: '../../layuiadmin/' //静态资源所在路径
      }).extend({
        index: 'lib/index' //主入口模块
        , my_send: '../myModules/my_send'
      }).use(['index', 'form','upload','layer','my_send'], function(){
        var $ = layui.$
        ,form = layui.form
        ,my_send = layui.my_send
        , http_proxy = layui.http_proxy;
        $.ajax({
            url:http_proxy('/materialCaregory/getDataTypeList'),
            async: false,
            dataType:'json',
            type:'get',
            success:function(data){
              $.each(data.rows,function(index,item){
                $('#typeList').append(new Option(item.fName,item.fId));
              });
              form.render('select');
            }
          });
    //监听提交
    form.on('submit(layuiadmin-app-form-submit)', function(data){
      var field = data.field; //获取提交的字段
      var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引  
      //提交 Ajax 成功后，关闭当前弹层并重载表格
      // field.fCaIsNull = field.fCaIsNull === '是' ? "1":"0",
      // field.fCaIsUniqueness = field.fCaIsUniqueness === '是' ? "1":"0",
      // field.fCaKeyField = field.fCaKeyField === '是' ? "1":"0";
      field.fMcId = jTools.getQuery('fMcId');
      $.ajax({
        url:http_proxy('/materialCaregory/saveMcAttr'),
        type:'post',
        dataType:'json',
        data:field,
        success:function (data) {
          if(data.code = "success"){
            layer.closeAll('loading');
            layer.load(2);
            layer.msg("新增成功", {icon: 6});
            window.parent.location.reload();
          }else{
              layer.msg("已经存在该设备,不支持重复添加", {icon: 5});
          }
        }
      });
      parent.layui.table.reload('LAY-app-content-list'); //重载表格
      parent.layer.close(index); //再执行关闭 
      });
    })
  </script>
</body>
</html>